from surprise import Dataset
from surprise import SVD
from surprise import KNNBasic
from surprise.model_selection import cross_validate


# 加载内置的movielens数据集
data = Dataset.load_builtin('ml-100k')

print(data)

# 获取训练集
trainset = data.build_full_trainset()

#algo = SVD()
algo = KNNBasic()
algo.fit(trainset)

uid = str(196)  # 用户ID
iid = str(302)  # 物品ID
pred = algo.predict(uid, iid)
print(f"预测评分: {pred.est}")


results = cross_validate(algo, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)
print("交叉验证结果:", results)